
import request from '../../../utils/request'

Page({
    data:{
        title: '',
        content: '',
        module: ['普通模板','生日模板'],
        index:0,
        order_id: 1
    },
    onLoad: function(e){
        console.log(e)
        this.setData({
            order_id: e.order_id
        })
    },
    onReady: function() {
        wx.setNavigationBarTitle({
            title: '生成邀请函'
        })
    },

    getTitle(e) {
        this.setData({
            title: e.detail.value
        })
    },
    getContent(e) {
        this.setData({
            content: e.detail.value
        })
    },
    bindModule(e){
        this.setData({
            index: e.detail.value
        })
    },
    createInvitation() {
        let data={
            "order_id": this.data.order_id,
            'title': this.data.title,
            'content': this.data.content,
            'templet': this.data.index,
            'token': wx.getStorageSync('sessionId')
        }
        request.HttpRequst(true,'buildinvitation',false,'',data,"POST",false,res => {
            console.log(res)
            if(res.code == 200){
                if(this.data.index == 0){
                    wx.navigateTo({
                        url: '../commonModel/commonModel?order_id='+this.data.order_id
                    })
                }else{
                    wx.navigateTo({
                        url: '../birthdayModel/birthdayModel?order_id='+this.data.order_id
                    })
                }
                
            }else{
                wx.showModal({
                    title: '提示',
                    content: res.info,
                    showCancel: false
                })
            }
        })
    },

    nosend() {
        wx.showModal({
            title: '提示',
            content: '你确定不用邀请函了吗？你将不能及时通知朋友预定的信息',
            success: function(res) {
                if(res.confirm){
                    wx.switchTab({
                        url: '/pages/index/index'
                    })
                }
            }
        })
    }

})